<?php

namespace app\api\controller;

use app\admin\model\Asset;
use app\api\controller\BaseClientController;
use support\Request;

class AssetController extends BaseClientController
{

    public $noNeedLogin = ['index'];

    public function index(Request $request)
    {
        // 资产列表
        $pageNum = $request->get("pageNum", 1);
        $pageSize = $request->get("pageSize", 10);
        $name = $request->get("name", "");

        $condition = [];
        // 若分类 ID 不为 0，则添加分类筛选条件
        if ($name) {
            $condition[] = ['name', 'like', "%$name%"];
        }
        // 使用 Products 模型进行分页查询，传入查询条件、页码和每页数量
        $paginator = Asset::paginate([
            'where' => $condition,
            'page' => $pageNum,
            'list_rows' => $pageSize,
        ]);

        // 从分页对象中获取当前页的商品列表
        $list = $paginator->items();
        // 从分页对象中获取商品的总数量
        $total = $paginator->total();

        // 返回包含商品列表和总数量的成功响应
        return $this->success([
            'list' => $list,
            'total' => $total,
        ]);

    }

}
